<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2021/1/15
 * Time: 10:21
 */

namespace app\api\controller;


use think\Db;

class Cpyinfo extends Base
{
    private $user_id; // 用户ID
    private $page; // 页码
    private $create_time;
    
    /**
     * 异地登录验证
     * @return string
     */
    public function __construct()
    {
        $this->user_id = input('user_id');
        $this->page = input('page') ? input('page') : 1;
        $this->create_time = date('Y-m-d H:i:s');
        $time = input('time');
        $value = input('value');
        $reqKey = input('reqKey');
        $auth = $this->checkAll($this->user_id, $time, $value, $reqKey);
        if($auth == 112){
            echo json_encode(['status' => 301, 'msg' => $this->otherLogin]);
            exit;
        }elseif($auth == 110){
            echo json_encode(['status' => 302, 'msg' => $this->frost]);
            exit;
        }elseif($auth == 2111){
            echo json_encode(['status' => 303, 'msg' => $this->del]);
            exit;
        }
    }
    
    /**
     * 企业资讯
     * @return \think\response\Json
     * limit    1 展示3条    2 列表
     * page         页码
     */
    public function infoList(){
        $limit = input('limit'); // 1 展示3条  2 列表
        $query = Db::table('up_company_info')
            ->field('ci_id, ci_title, ci_thumb, ci_is_top, ci_date')
            ->order('ci_is_top asc, ci_sort desc, ci_time desc');
        if($limit == 1){
            $query->limit(3);
        }else{
            $query->page($this->page, 10);
        }
        $data = $query->select();
        if($data){
            return json(['status' => 200, 'msg' => $data]);
        }else{
            return json(['status' => 200, 'msg' => []]);
        }
    }
    
    /**
     * 企业资讯详情
     * @return \think\response\Json
     * ci_id     企业资讯ID
     */
    public function infoDetail(){
        header("Access-Control-Allow-Origin: *");
        $ci_id = input('ci_id');
        $detail = Db::table('up_company_info')
            ->field('ci_title, ci_thumb, ci_content, ci_is_top, ci_date')
            ->where('ci_id', $ci_id)
            ->find();
        return json(['status' => 200, 'msg' => $detail]);
    }
}